package com.usian.login.lister;

import cn.hutool.core.util.RandomUtil;
import com.usian.third.code.AliCodeUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RabbitLister {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues = "java-queue")
    public void  sendLoginCode(Message message,String phone) throws Exception {
        AliCodeUtils aliCodeUtils = new AliCodeUtils();
        String code = RandomUtil.randomNumbers(6);
        aliCodeUtils.sendLoginCode(phone,code);
        stringRedisTemplate.opsForValue().set(phone,code);
        stringRedisTemplate.expire(phone,5, TimeUnit.MINUTES);
    }

//    public static void main(String[] args) {
//        String code = RandomUtil.randomNumbers(6);
//        System.out.println(code);
//    }
}
